package main

import (
	"fmt"
	"math/rand"
	"time"
)

// 简单的生产者消费者

func producer(head string, channel chan<- string) {
	for {
		channel <- fmt.Sprintf("name: %s, randNumber:%d", head, rand.Int31())
		time.Sleep(1 * time.Second)
	}
}

func consumer(channel <-chan string) {
	for {
		fmt.Println(<-channel)
	}
}

func main() {

	channel := make(chan string)
	go producer("dog", channel)
	go producer("cat", channel)
	consumer(channel)
}
